//
//  UIButton+Addition.m
//  THCustomer
//
//  Created by lichentao on 13-8-13.
//  Copyright (c) 2013年 efuture. All rights reserved.
//

#import "UIButton+Addition.h"
#import "BPCommon.h"
@implementation UIButton (Addition)
// 默认返回back 图片
+ (UIButton *)backButtonWithTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents {
	return [UIButton backButtonWithImage:@"back" target:target action:action forControlEvents:controlEvents];
}

// left image
+ (UIButton *)backButtonWithImage:(NSString *)image target:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents {
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame           = CGRectMake(0.0f, 0.0f, 46/2, 46.0f/2);
    backButton.titleLabel.shadowColor = [UIColor whiteColor];
   [backButton setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    [backButton addTarget:target action:action forControlEvents:controlEvents];
    return backButton;
}

// left title
+ (UIButton *)backButtonWithTitle:(NSString *)title target:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents {
	UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
	UIFont   *titleFont  = [UIFont systemFontOfSize:14];
	backButton.frame           = CGRectMake(0.0f, 0.0f, 46, 46);
	backButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
	backButton.titleLabel.font = titleFont;
	backButton.titleLabel.shadowColor = [UIColor whiteColor];
	backButton.titleLabel.shadowOffset = CGSizeMake(0, -1.0);
	[backButton setTitle:title forState:UIControlStateNormal];
    [backButton setTitleColor:[BPCommon colorWithHexValue:0xfd9800 alpha:1.0f] forState:UIControlStateNormal];
	[backButton addTarget:target action:action forControlEvents:controlEvents];
	return backButton;
}

// right title
+ (UIButton *)rightButtonWithTitle:(NSString *)title target:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents {
	UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
	UIFont   *titleFont   = [UIFont systemFontOfSize:14];

   CGSize size = [title sizeWithAttributes:@{NSFontAttributeName:titleFont}];
    rightButton.frame = CGRectMake(0.0f, 0.0f, size.width, 23);
	rightButton.titleLabel.font = titleFont;
	rightButton.titleLabel.shadowColor = [UIColor blackColor];
	rightButton.titleLabel.shadowOffset = CGSizeMake(0, -1.0);
	[rightButton setTitle:title forState:UIControlStateNormal];
    [rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    [rightButton setBackgroundImage:[UIImage imageNamed:title] forState:UIControlStateNormal];
	[rightButton addTarget:target action:action forControlEvents:controlEvents];
	return rightButton;
}


@end
